//
//  MainController.swift
//  NHFX-Swift
//
//  Created by 王磊 on 2017/7/11.
//  Copyright © 2017年 王磊. All rights reserved.
//

import UIKit

class MainController: UITabBarController {
    var tabbarView = UIView()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.red
        creatUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    func creatUI() {
        //自定义tabbar
        tabbarView = UIView.init(frame: self.tabBar.bounds)
        tabbarView.isUserInteractionEnabled = true
        tabbarView.backgroundColor = UIColor.white
        tabBar.addSubview(tabbarView)
        
        let titleAry = ["商品","我的"]
        let normalImage = ["goods_normael1","home_normael1"]
        let selectedImage = ["goods_selected", "home_selected"]
        let VCary = ["NHGoodsViewController", "NHHomeViewController"]
        
        for i in 0..<VCary.count {
            let str = VCary[i]
            
            
        }
        
        
    }
    
   private func addChildViewController(childControllerName: String) -> NHNavigationController? {
        // 1.获取命名空间
        guard let clsName = Bundle.main.infoDictionary!["CFBundleExecutable"] else {
            print("命名空间不存在")
            return nil
        }
        // 2.通过命名空间和类名转换成类
        let cls : AnyClass? = NSClassFromString((clsName as! String) + "." + childControllerName)
        
        // swift 中通过Class创建一个对象,必须告诉系统Class的类型
        //guard只有在条件不满足的时候才会执行这段代码
        guard let clsType = cls as? UIViewController.Type else {
            print("无法转换成UIViewController")
            return nil
        }
        
        // 3.通过Class创建对象
        let childController = clsType.init()
        
        // 包装导航控制器
        let nav = NHNavigationController(rootViewController: childController)
        
        return nav

    }

}
